<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/common/common.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 
  <head>
    <base href="<%=basePath%>" />
    <title>User complaints management</title>
    <script type="text/javascript">
		var path = "<%=basePath%>";
	</script>
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3" />
	<meta http-equiv="description" content="This is my page" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>beshs/css/content.css" />
	<script type="text/javascript" src="<%=basePath%>resources/jquery/jquery-1.7.2.min.js"></script>
	<!-- 系统通用资源 -->
	<jsp:include page="/resources/resource-refer/common-resource-reference.jsp" />
	<script type="text/javascript" src="<%=basePath%>resources/common.js"></script>
  </head>
  <script type="text/javascript">
  	function formVerify() {
  		//楼栋名称
  		var buildingName = trim($("input[name='userComplaint.complaintTitle']").val()); 
  		if(buildingName==null || $.trim(buildingName)=="") {
  			showWrongPic("input","userComplaint.complaintTitle",path);
  			$("input[name='userComplaint.complaintTitle']").select();
  			$("input[name='userComplaint.complaintTitle']").focus();
  			return false;
  		} else {
  			showRightPic("input","userComplaint.complaintTitle",path);
  			if(isQuoteIn(buildingName)){
	  			showWrongPic("input","userComplaint.complaintTitle",path);
	  			alert("The title you entered contains special characters, please re-enter！");
  				$("input[name='userComplaint.complaintTitle']").select();
  				$("input[name='userComplaint.complaintTitle']").focus();
	  			return false;
  			}
  		}
  		//楼栋编号
  		var buildingID = trim($("textarea[name='userComplaint.userComplaint']").val()); 
  		if(buildingID == "The complaint does not exceed 500 words"){
  			buildingID="";
  		}
  		if(buildingID==null || $.trim(buildingID)=="") {
  			showWrongPic("textarea","userComplaint.userComplaint",path);
  			$("textarea[name='userComplaint.userComplaint']").select();
  			$("textarea[name='userComplaint.userComplaint']").focus();
  			return false;
  		} else {
  			showRightPic("textarea","userComplaint.userComplaint",path);
  			if(isQuoteIn(buildingID)){
	  			showWrongPic("textarea","userComplaint.userComplaint",path);
	  			alert("The complaint you entered contains special characters, please re-enter！");
  				$("textarea[name='userComplaint.userComplaint']").select();
  				$("textarea[name='userComplaint.userComplaint']").focus();
	  			return false;
  			}
  		}
  		return true;
  	}
  
  function submitForm() {
  		//表单校验
  		var verify = formVerify();
  		if(!verify) return;
  		//表单信息
  		var title = $("input[name='userComplaint.complaintTitle']").val(); 
  		var content = $("textarea[name='userComplaint.userComplaint']").val();
  		$.getJSON(path+"beshs/customerComplaintsActionJson!saveCustomerComplaint.do?date="+new Date(), {
  			"userComplaint.complaintTitle": title,
  			"userComplaint.userComplaint": content
  		}, function(data){
  			if(data.success) {
  				Dialog.alert("Operation success！", function() {
  					var index = parent.layer.getFrameIndex(window.name)
					parent.window.frames["c_content_content"].location = path + "beshs/customerComplaintsAction!queryForPage.do?date="+new Date();
  					parent.layer.close(index);
  				});
  			} else {
  				Dialog.alert(data.msg);
  			}
  		});
  	}
  	$(function(){
  		$("input[name='submit']").click(function(){
  			submitForm();
  		});
  	});
</script>
<body>
    <div class="content_all">
  		<!--导航条-->
  		<div class="insertinfo_table">
      		<form action="#">
      		  <input name="userComplaint.userId" type="hidden" value="<s:property value='userComplaint.userId' />" />
      		  <table width="100%" border="0" cellspacing="0" cellpadding="0">
        		<tr>
        			<th>User name：</th>
          			<td><input name="userComplaint.loginName" type="text" class="s_input" value="<s:property value='userComplaint.loginName' />"  disabled="disabled"/>
            			&nbsp;<span style="color:#FF0000;">*</span></td>
            		<th>headings：</th>
          			<td><input name="userComplaint.complaintTitle" type="text" class="s_input" value="<s:property value='userComplaint.complaintTitle' />" maxlength="20" />
            			&nbsp;<span style="color:#FF0000;">*&nbsp;(No more than 20 words)</span></td>
            	</tr>
        		<tr>
          			<th>The complaint content：</th>
          			<td colspan="3">
          			<textarea rows="5" cols="70" name="userComplaint.userComplaint" onfocus="showMsg(1);" id="complaint" onblur="showMsg(2)">The complaint does not exceed 500 words</textarea>
            			&nbsp;<span style="color:#FF0000;">*&nbsp;</span></td>
        		</tr>
        		<tr>
          			<td style="border:none;" colspan="4" align="center">
          				<input name="submit" type="submit" value="submit" class="s_btn" onclick="return formVerify();" />
            			<input name="reset" type="reset" value="reset" class="s_btn"/></td>
        		</tr>
      		  </table>
      		</form>
  		</div>
	</div>
	<div class="clear"></div>
  </body>
<script type="text/javascript">
function showMsg(data){
	var comp = $("#complaint");
	if(data == 1 && comp.val() == "The complaint does not exceed 500 words"){
		comp.val("");
	}
	if(data == 2 && comp.val() == ""){
		comp.val("The complaint does not exceed 500 words");
	}
}
</script>
</html>
